<?php
/*=====================================================
 Copyright (C) ETERNAL<iqstar@ms24.hinet.net>
 URL : http://www.et99.net

请仔细阅读以下许可协议。当您使用本软体，您将自动成为本协议的一方并受到本协议的约束。

软体和文档受到台湾及中国大陆著作权法及国际条约的保护。您不得：
a)营利、出租或者出借软体或文档的任何部分。
b)反向工程、分解、反编译或者企图察看软体的源代码作为商业用途。
c)修改或者改变软体，或者与其他程式结合。

许可人保留软体及文档的所有权利和权益。您不能通过本许可协定获得软体的任何所有权和知识产权。
===================================================== */
header('Content-Type:text/html;charset=utf8');

class wog_act_store
{
    var $fight_hotel = 0;

    /**
     * 住宿
     * @param $user_id
     */
    function hotel($user_id)
    {
        global $DB_site, $wog_array, $lang, $_SESSION;
        $have_price = $DB_site->query_first("select p_money,p_lv,hp,hpmax,p_win,p_lost,au,p_st from wog_player where p_id=" . $user_id);
        $mmoney = 0;
        $mexp = 0;
        if ($have_price['p_lv'] > $wog_array["hotel_free_lv"]) {
            // 倍率
            $slv = $have_price['hp'] <= 0 ? ($wog_array['hotel_die_price_mag'] <= 1 ? 1 : $wog_array['hotel_die_price_mag']) : 1;
            $reset_hp = $have_price['hpmax'] - $have_price['hp'];
            // 死亡时
            if ($have_price['hp'] <= 0) {
                $reset_hp = $have_price['hpmax'];
            }
            echo('<br>');
            echo('所需恢复hp：' . $reset_hp);
            if ($reset_hp > 0) {
                $mmoney += ($reset_hp + $have_price['p_lv']) * $wog_array['hotel_hp_price'] * $slv;
                echo('<br>');
                echo('HP单价费用（带死亡翻倍）：' . $mmoney);
                $mmoney -= $have_price['au'] * $wog_array['hotel_au_discount'];
                echo('<br>');
                echo('减去au优惠：' . ($have_price['au'] * $wog_array['hotel_au_discount']) . ':' . $mmoney);
            }
            $mmoney += $wog_array['hotel_money'];
            echo('<br>');
            echo('加入住宿费用：' . $wog_array['hotel_money'] . ':' . $mmoney);
//            会员折扣
            $mmoney = $mmoney < 0 ? $wog_array['hotel_money'] : round($mmoney * $wog_array['hotel_vip_discount'][$have_price['p_st']]);
            echo('<br>');
            echo('住宿费用：' . $mmoney);
            echo('<br>');
            // 魅力影响
//            $have_price['hpmax'] = $have_price['hpmax'] - ($have_price['p_au'] * 2);
//            if ($have_price['hp'] > $have_price['hpmax']) {
//                $have_price['hp'] = $have_price['hpmax'];
//            }
//            if ($have_price['hp'] <= 0) {
//                $slv = 2;
//                $hotel_time = $wog_array["hotel_die_time"];
//            } else {
//                if (($have_price['hpmax'] / 10) > $have_price[hp]) {
//                    $slv = 1.8;
//                } else {
//                    $slv = 1.4 * (($have_price['hpmax'] - $have_price['hp']) / $have_price['hpmax']);
//                }
//                $hotel_time = $wog_array["hotel_time"];
//            }
//            $mmoney = round($wog_array["hotel_money"] * $have_price['p_lv'] * $slv);
//            if ($mmoney < ($wog_array["hotel_money"] * $have_price['p_lv'])) {
//                $mmoney = $wog_array["hotel_money"] * $have_price['p_lv'];
//            }
            if ($have_price['p_money'] < $mmoney) {
                $mexp = $have_price['p_exp'] * $wog_array['hotel_no_money_need_exp'];
                $have_exp = $have_price['p_exp'] - $mexp;
                $DB_site->query("update wog_player set hp=hpmax,p_exp={$have_exp},sp=spmax where p_id=" . $user_id);
//				alertWindowMsg(sprintf($lang['wog_act_nomoney_must'], $mmoney));
            } else {
                $have_money = $have_price['p_money'] - $mmoney;
                $DB_site->query("update wog_player set p_money=" . $have_money . ",hp=hpmax,sp=spmax where p_id=" . $user_id);
            }
        } else {
            $DB_site->query("update wog_player set hp=hpmax,sp=spmax where p_id=" . $user_id);
            if ($have_price['hp'] <= 0) {
                $hotel_time = $wog_array["hotel_die_time"];
            } else {
                $hotel_time = $wog_array["hotel_time"];
            }
        }
        $_SESSION["act_time"] += $hotel_time;
        $result_msg = $have_price['p_money'] < $mmoney ? "消耗经验<strong class=\"text-prompt font-size-16\">{$mexp}</strong>" : "消耗金钱<strong class=\"text-prompt font-size-16\">{$mmoney}</strong>";
        /*
        if(time()-$_SESSION["act_time"] > $wog_array["f_time"])
        {
            $_SESSION["act_time"]=time()-($wog_array["f_time"]-$wog_array["hotel_time"]);
        }else
        {
            $_SESSION["act_time"]+=$wog_array["hotel_time"];
        }
        */
//        if ($this->fight_hotel) {
//            echo ",\"parent.job_end(5,null,2)\",\"parent.cd(" . $hotel_time . ")\"";
//        } else {
//        showscript("parent.job_end(5,null,2);parent.cd(" . $hotel_time . ")");
        return "parent.job_end(5,'{$result_msg}',2);";
//        }
    }

    function bank($user_id)
    {
        global $DB_site, $_POST, $lang;
        $have_price = $DB_site->query_first("select p_bbsid,p_money from wog_player where p_id=" . $user_id);
        $bank_price = $DB_site->query_first("select " . BANK_FIELB . " from " . BANK_TABLE . " where " . USER_ID . "=" . $user_id);
        showscript("parent.bank('" . $have_price[p_money] . "','" . $bank_price[0] . "')");
    }

    function bank_save($user_id, $pay_id, $money)
    {
        global $DB_site, $lang;
        $DB_site->query_first("set autocommit=0");
        $DB_site->query_first("BEGIN");
        $have_price = $DB_site->query_first("select p_name,p_money,p_lv,p_bbsid from wog_player where p_id=" . $user_id . " for update");
        if ($have_price[p_money] < $money || $money <= 0 || $have_price[p_lv] < 15 || !is_numeric($money) || preg_match("/[^0-9]/", $money)) {
            alertWindowMsg($lang['wog_act_bank_noues']);

        } else {
            if ($user_id != $pay_id) {
                $DB_site->query("insert into wog_message(p_id,title,dateline)values(" . $pay_id . ",'" . $have_price[p_name] . " 汇入 " . $money . "元 到你的银行 '," . time() . ")");
                //$p=$DB_site->query_first("select p_bbsid from wog_player where p_id=".$pay_id);
                $DB_site->query("update " . BANK_TABLE . " set " . BANK_FIELB . " = " . BANK_FIELB . "+" . $money . " WHERE " . USER_ID . "=" . $pay_id);
            } else {
                $DB_site->query("update " . BANK_TABLE . " set " . BANK_FIELB . " = " . BANK_FIELB . "+" . $money . " WHERE " . USER_ID . "=" . $user_id);
            }
            $DB_site->query("update wog_player set p_money = p_money-" . $money . " where p_id=" . $user_id);
        }
        $DB_site->query_first("COMMIT");
        showscript("parent.job_end(4)");
    }

    function bank_get($user_id, $money)
    {
        global $DB_site, $lang;
        $DB_site->query_first("set autocommit=0");
        $DB_site->query_first("BEGIN");
        $bank_memey = $DB_site->query_first("select " . BANK_FIELB . " from wog_player where p_id=" . $user_id . "  for update ");
        if ($bank_memey[BANK_FIELB] < $money) {
            alertWindowMsg($lang['wog_act_nomoney']);
        }
        if ($bank_memey[BANK_FIELB] < $money || $money <= 0 || !is_numeric($money) || preg_match("/[^0-9]/", $money)) {
            alertWindowMsg($lang['wog_act_nomoney']);
        } else {
            $DB_site->query("update " . BANK_TABLE . " set " . BANK_FIELB . " = " . BANK_FIELB . "-" . $money . " WHERE " . USER_ID . "=" . $user_id);
            $DB_site->query("update wog_player set p_money = p_money+" . $money . " where p_id=" . $user_id);
        }
        $DB_site->query_first("COMMIT");
        showscript("parent.job_end(4)");
    }

    function p_sex($user_id)
    {
        global $DB_site, $_POST, $wog_array, $lang;
        if (empty($_POST["num"])) {
            alertWindowMsg($lang['wog_act_img_nosexg']);
        }
        if (preg_match("/[12]/", $_POST["num"])) {
            $have_price = $DB_site->query_first("select p_money from wog_player where p_id=" . $user_id . "");
            if ($wog_array["chang_sex"] > $have_price[0]) {
                alertWindowMsg($lang['wog_act_nomoney']);
            }
            $DB_site->query("update wog_player set p_sex=" . $_POST["num"] . ",p_money=p_money-" . $wog_array["chang_sex"] . " where p_id=" . $user_id . "");
            showscript("parent.job_end(11)");
        } else {
            alertWindowMsg($lang['wog_act_img_errsex']);
        }
        unset($have_price);
    }

    function p_img($user_id)
    {
        global $DB_site, $_POST, $wog_array, $lang;
        if (empty($_POST["num"])) {
            alertWindowMsg($lang['wog_act_img_noimg']);
        }
        if (!is_numeric($_POST["num"])) {
            alertWindowMsg($lang['wog_act_img_errimg']);
        }
        $p = $DB_site->query_first("SELECT i_id FROM wog_img WHERE i_id=" . $_POST["num"] . " ");
        if ($p) {
            $have_price = $DB_site->query_first("select p_money from wog_player where p_id=" . $user_id . "");
            if ($wog_array["chang_face"] > $have_price[0]) {
                alertWindowMsg($lang['wog_act_nomoney']);
            }
            $DB_site->query("update wog_player set p_img_set=0,i_img=" . $_POST["num"] . ",p_money=p_money-" . $wog_array["chang_face"] . " where p_id=" . $user_id . "");
            showscript("parent.job_end(11)");
        } else {
            alertWindowMsg($lang['wog_act_img_errimg']);
        }
        unset($p, $have_price);
    }

    function p_img2($user_id)
    {
        global $DB_site, $_POST, $wog_array, $lang;
        if (empty($_POST["url"])) {
            alertWindowMsg($lang['wog_act_img_noimg']);
        }
        $have_price = $DB_site->query_first("select p_money,p_st from wog_player where p_id=" . $user_id . "");
        if ($wog_array["chang_face"] > $have_price['p_money']) {
            alertWindowMsg($lang['wog_act_nomoney']);
        }
        /*
                if($have_price['p_st']<2){
                    alertWindowMsg($lang['wog_vip_message']);
                }
        */
        $DB_site->query("update wog_player set p_img_set=1,p_img_url='" . $_POST["url"] . "',p_money=p_money-" . $wog_array["chang_face"] . " where p_id=" . $user_id . "");
        showscript("parent.job_end(11)");
        unset($have_price);
    }
}

?>